﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;
using System.Collections;

namespace DAO
{
    public class NhaCungCapDAO
    {
        /// <summary>
        /// Lay thong tin chi tiet cua 1 nha cung cap theo ma nha cung cap
        /// </summary>
        /// <param name="mancc"></param>
        /// <returns></returns>
        /// <proc>sp_NhaCungCap_layThongTinNhaCungCapTheoMaNCC</proc>
        public NhaCungCapDTO layThongTinNhaCungCap(string mancc)
        {
            List<string> paraLst = new List<string>();
            ArrayList valueArr = new ArrayList();
            paraLst.Add("@mancc");
            valueArr.Add(mancc);
            try
            {
                DataTable dt = DataProvider.ExecuteStoreProc("sp_NhaCungCap_layThongTinNhaCungCapTheoMaNCC", paraLst, valueArr);
                if (dt.Rows.Count == 0)
                    return null;
                NhaCungCapDTO ncc = new NhaCungCapDTO();
                ncc.DiaChi = dt.Rows[0]["DiaChi"].ToString();
                ncc.LoaiNCC = dt.Rows[0]["LoaiNCC"].ToString();
                ncc.MaNCC = dt.Rows[0]["MaNCC"].ToString();
                ncc.SDT = dt.Rows[0]["SDT"].ToString();
                ncc.TaiKhoanNgaHnang = dt.Rows[0]["TaiKhoanNganHang"].ToString();
                ncc.TenNCC = dt.Rows[0]["TenNCC"].ToString();
                ncc.TenNganHang = dt.Rows[0]["TenNganHang"].ToString();
                ncc.HeSoGia = float.Parse(dt.Rows[0]["HeSoGia"].ToString());
                ncc.DonViTinh = dt.Rows[0]["DonViTinh"].ToString();
                return ncc;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// Lay thong tin nha cung cap theo loai nha cung cap
        /// Gom cac loai: Cong ty du lich, Dich vu hang khong, Dich vu van chuyen, Dich vu khach san
        /// </summary>
        /// <param name="loaiNCC">Loai nha cung cap</param>
        /// <returns></returns>
        /// <proc>sp_NhaCungCap_layThongTinNhaCungCapTheoLoaiNCC</proc>
        public List<NhaCungCapDTO> layThongTinNhaCungCapTheoLoaiNCC(string loaiNCC)
        {
            List<string> paraLst = new List<string>();
            ArrayList valueArr = new ArrayList();
            paraLst.Add("@loaincc");
            valueArr.Add(loaiNCC);
            try
            {
                DataTable dt = DataProvider.ExecuteStoreProc("sp_NhaCungCap_layThongTinNhaCungCapTheoLoaiNCC", paraLst, valueArr);
                if (dt.Rows.Count == 0)
                    return null;
                List<NhaCungCapDTO> nccLst = new List<NhaCungCapDTO>();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    NhaCungCapDTO ncc = new NhaCungCapDTO();
                    ncc.DiaChi = dt.Rows[i]["DiaChi"].ToString();
                    ncc.LoaiNCC = dt.Rows[i]["LoaiNCC"].ToString();
                    ncc.MaNCC = dt.Rows[i]["MaNCC"].ToString();
                    ncc.SDT = dt.Rows[i]["SDT"].ToString();
                    ncc.TaiKhoanNgaHnang = dt.Rows[i]["TaiKhoanNganHang"].ToString();
                    ncc.TenNCC = dt.Rows[i]["TenNCC"].ToString();
                    ncc.TenNganHang = dt.Rows[i]["TenNganHang"].ToString();
                    ncc.HeSoGia = float.Parse(dt.Rows[i]["HeSoGia"].ToString());
                    ncc.DonViTinh = dt.Rows[i]["DonViTinh"].ToString();
                    nccLst.Add(ncc);
                }                
                return nccLst;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
